import random
# 生成中奖号码
winning_numbers = random.sample(range(1, 34), 8)
# 用户输入号码
input_numbers = []
try:
    for i in range(8):
        num = int(input("请输入第{}个数字：".format(i + 1)))
        if num < 1 or num > 33:
            print("输入数字不在1-33之间，请重新输入！")
            break
        input_numbers.append(num)
    else:
        print("您输入的数字为：", input_numbers)
        # 判断是否中奖
        count = 0
        for i in input_numbers:
            if i in winning_numbers:
                count += 1
        if count == 8:
            print("恭喜您中了一等奖！")
        elif count == 7:
            print("恭喜您中了二等奖！")
        elif count == 6:
            print("恭喜您中了三等奖！")
        elif count >= 4:
            print("恭喜您中了四等奖！")
        else:
            print("很遗憾，您没有中奖！")
except ValueError:
    print("输入的不是数字，请重新输入！")
# 模拟随机购买10000注彩票
count1, count2, count3, count4, count5 = 0, 0, 0, 0, 0
for i in range(10000):
    # 生成一注彩票
    ticket = random.sample(range(1, 34), 8)
    # 判断是否中奖
    count = 0
    for j in ticket:
        if j in winning_numbers:
            count += 1
    if count == 8:
        count1 += 1
    elif count == 7:
        count2 += 1
    elif count == 6:
        count3 += 1
    elif count >= 4:
        count4 += 1
    else:
        count5 += 1
# 输出中奖概率
print("一等奖中奖概率为：{:.4f}%".format(count1 / 100))
print("二等奖中奖概率为：{:.4f}%".format(count2 / 100))
print("三等奖中奖概率为：{:.4f}%".format(count3 / 100))
print("四等奖中奖概率为：{:.4f}%".format(count4 / 100))
print("未中奖的概率为：{:.4f}%".format(count5 / 100))